
import type { PayParams } from '@/types/components'
import type { RateParams } from '@/types/consult'
import type { UploadImage } from '@/types/user'
import { request } from '@/utils/http'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export interface ConsultInfo {
  illnessDesc: string
  illnessTime: number
  consultFlag: number
  pictures: UploadImage[]
}

export const useConsultStore = defineStore(
  'consult',
  () => {
    const initData: ConsultInfo = {
      illnessDesc: '',
      illnessTime: 0,
      consultFlag: 1,
      pictures: [],
    }

    const illnessInfo = ref<ConsultInfo>({ ...initData })

    const depId = ref('')
    const illnessType = ref('')
    const type = ref('')
    // 患者id
    const patientId = ref('')

    // 清空 store
    const clear = () => {
      // 重置对象数据
      illnessInfo.value = { ...initData }
      // 重置普通数据
      type.value = ''
      depId.value = ''
      illnessType.value = ''
      patientId.value = ''
    }

    return { illnessInfo, type, depId, illnessType, patientId, clear }
  },
  { unistorage: true }
)

/**
 * 三方支付（暂时只支持支付宝支付）
 */
export const orderPayApi = (data: PayParams) => {
  return request.post<null, {payUrl:string}>('/patient/consult/pay', data)
}

/**
 * 评价医生
 */
export const evaluateDoctorApi = (data:RateParams) => {
  return request.post('/patient/order/evaluate', data)
}